<template>
    <div class="notice">
        <img src="/src/assets/image/喇叭.png" @click="lookNotice">
        <div class="scroll-text" v-if="store.NoticeList">
            <span>{{ store.NoticeList[0].text }}</span>
        </div>
    </div>
    <div class="container" v-if="store.isNotice">
        <el-card style="width: 680px">
            <template #header>
                <div class="card-header">
                    <h3>公告信息</h3>
                </div>
            </template>
            <el-form label-width="auto" style="max-width: 600px">
                <el-form-item label="发布时间(xxxx年xx月xx日)">
                    <el-input v-model="time" />
                </el-form-item>
                <el-form-item label="公告内容">
                    <el-input type="textarea" v-model="text" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="addOK">确认发布</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-button type="danger" class="close" @click="close">X</el-button>
    </div>
</template>

<script setup>
import { mapStore } from '@/store';
import { ref } from 'vue';
const store = mapStore()
const time = ref()
const text = ref()

const addOK = () => {
    store.NoticeList.splice(0, 0, {
        time: time.value,
        text: text.value,
    })
    store.isNotice = false
    console.log(store.NoticeList)
}

const close = () => {
    store.isNotice = false
}

const lookNotice = () => {
    store.isLook = true
}
</script>

<style scoped lang="scss">
.container {
    position: fixed;
    top: 15%;
    left: 30%;
    z-index: 1000;

    h3 {
        text-align: center;
    }

    .close {
        position: absolute;
        top: 0;
        right: 0%;
        z-index: 1000;

    }
}

.notice {
    display: flex;
    justify-content: space-between;
    position: fixed;
    top: 10%;
    left: 30%;
    width: 600px;
    height: 30px;
    z-index: 1000;
    background: #3592a79c;
    border-radius: 10px;
    white-space: nowrap;
    /* 防止文字换行 */
    overflow: hidden;
    /* 隐藏溢出的内容 */


    span {
        line-height: 30px;
        color: #fff
    }

    img {
        width: 30px;
        height: 30px;
        position: fixed;
        top: 70px;
        left: 420px;
        cursor: pointer;
    }

    .scroll-text {
        white-space: nowrap;
        /* 防止文字换行 */
        overflow: hidden;
        /* 隐藏溢出的内容 */
        animation: scroll-left 20s linear infinite;
        /* 使用scroll-left动画,线性无限循环 */
    }

    @keyframes scroll-left {
        0% {
            transform: translateX(150%);
        }

        /* 初始位置 */
        100% {
            transform: translateX(-100%);
        }

        /* 最终位置 */
    }
}
</style>
